use super::hdc_error::{HdcError, HdcErrorKind};

#[derive(Debug, PartialEq, Clone, Copy)]
#[repr(u64)]
pub enum HdcCommand {
    Client = 1,
    Daemon,
    Server,
}

impl TryFrom<u64> for HdcCommand {
    type Error = HdcError;

    fn try_from(value: u64) -> Result<Self, Self::Error> {
        match value {
            1 => Ok(Self::Client),
            2 => Ok(Self::Daemon),
            3 => Ok(Self::Server),
            _ => {
                let msg = format!("HdcCommand try_from failed, value {value}");
                log::error!("{msg}");
                Err(HdcError::new(HdcErrorKind::HdcInvalidData, msg))
            }
        }
    }
}
